<template>
  <div>
    <el-row>
      <el-col :span="24">
        <section-title
          title="负载监控"
          icon-class="el-icon-s-data"
        ></section-title>
      </el-col>
    </el-row>
    <!--    条件框-->
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-row>
        <el-col :span="20" align="left" :offset="1">
          <el-form-item label="查询方式" prop="status">
            <el-select
              v-model="queryParams.selectMethod"
              size="small"
              style="width: 240px"
              @change="selectMethodChang"
            >
              <el-option
                v-for="item in queryParams.selectMethods"
                :key="item.method"
                :label="item.name"
                :value="item.method"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="开始时间:">
            <el-date-picker
              v-model="queryParams.startTime"
              align="right"
              type="date"
              placeholder="开始时间"
              :picker-options="pickerOptions"
              :disabled="showDate"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="结束时间">
            <el-date-picker
              v-model="queryParams.endTime"
              align="right"
              type="date"
              placeholder="开始时间"
              :picker-options="pickerOptions"
              :disabled="showDate"
            ></el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :span="3">
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
            >
              搜索
            </el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
              重置
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <!--    图表-->
    <el-row>
      <el-col :span="24">
        <hight-charts-histogram
          :charts-data="chartsData"
        ></hight-charts-histogram>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import sectionTitle from '@/components/SectionTitle'
  import HightChartsHistogram from '@/views/cluster-monitor/compoents/HightChartsHistogram'

  export default {
    name: 'LoadMonitor',
    components: { HightChartsHistogram, sectionTitle },
    props: {
      title: {
        type: String,
        default: 'chart',
      },
      chartsData: {
        type: Object,
        default: () => {},
      },
    },
    data() {
      return {
        queryParams: {
          selectMethod: 'period', //选中的查询方式
          selectMethods: [
            //查询方式列表
            { method: 'period', name: '按照时间段统计' },
            { method: 'runing', name: '在执行项目负载统计' },
            { method: 'today', name: '当天负载情况查看' },
          ],
          startTime: '',
          endTime: '',
        },
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now()
          },
          shortcuts: [
            {
              text: '今天',
              onClick(picker) {
                picker.$emit('pick', new Date())
              },
            },
            {
              text: '昨天',
              onClick(picker) {
                const date = new Date()
                date.setTime(date.getTime() - 3600 * 1000 * 24)
                picker.$emit('pick', date)
              },
            },
            {
              text: '一周前',
              onClick(picker) {
                const date = new Date()
                date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
                picker.$emit('pick', date)
              },
            },
          ],
        },
      }
    },
    computed: {
      //日期栏是否可选
      showDate: function () {
        return this.queryParams.selectMethod != 'period'
      },
    },
    created() {},
    methods: {
      //执行查询
      handleQuery: function () {
        console.log(this.queryParams)
        console.log(this.target)
      },
      //重置搜索条件
      resetQuery: function () {
        this.queryParams.selectMethod = 'now'
        this.queryParams.showMethod = 'minute'
        this.queryParams.startTime = null
        this.queryParams.endTime = null
      },
      //查询方式改变
      selectMethodChang: function () {
        if (this.queryParams.selectMethod != 'period') {
          this.queryParams.startTime = null
          this.queryParams.endTime = null
        }
      },
    },
  }
</script>

<style scoped></style>
